﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lidgren.Network;

namespace Model.LiveControl
{
    public struct ProccessInfo:ISerializable
    {
        public string Name;
        public int Ptr;

        public void WritePayload(NetOutgoingMessage message)
        {
            message.Write(Name);
            message.Write(Ptr);
        }

        public void ReadPayload(NetIncomingMessage message)
        {
            Name = message.ReadString();
            Ptr = message.ReadInt32();
        }

        public override string ToString()
        {
            return $"{Name}:{Ptr}";
        }
    }
    public  class ProccessInfoList:ISerializable
    {
        public ProccessInfo[] ProccessInfos;
        public void WritePayload(NetOutgoingMessage message)
        {
            message.Write(ProccessInfos.Length);
            foreach (var proccessInfo in ProccessInfos)
            {
                proccessInfo.WritePayload(message);
            }
        }

        public void ReadPayload(NetIncomingMessage message)
        {
            var count = message.ReadInt32();
            ProccessInfos = new ProccessInfo[count];
            for (var i = 0; i < count; i++)
            {
                ProccessInfos[i].ReadPayload(message);
            }
        }
    }
}
